<?php
	include_once("db/PayStation.inc");
	include_once("db/AuditLogs.inc");
	
	$ps = new PayStation();
	
	$ps->payStationCode = $_REQUEST["id"];
	$ps->ministryId = $_REQUEST["ministryId"];
	$ps->deptCode = $_REQUEST["deptCode"];
	$ps->description = $_REQUEST["description"];
	$ps->regionCode = $_REQUEST["region"];
	$ps->provinceCode = $_REQUEST["province"];
	$ps->districtCode = $_REQUEST["district"];
	
	/*
	 * Check if the paystation code already exists.  If so, redirect back to the add pay station page with
	 * an error.
	 */
	if (PayStation::getPaystation($ps->ministryId, $ps->deptCode, $ps->payStationCode) != null) {
		header("Location: ?action=newPayStation&error=payCodeExists");
	} else {
		PayStation::newPayStation($ps);
		AuditLogs::insertLog(User::getUser($_SESSION["uid"])->username, 'admin - add pay station',
			"ID='".$ps->payStationCode."' Ministry='".$ps->ministryId."' Department='".$ps->deptCode.
			"' Region='".$ps->regionCode."' Province='".$ps->provinceCode."' District Code='".
			$ps->districtCode."' Description='".str_replace("'", "''", $ps->description)."'");
		
		header("Location: ./?action=viewPayStations");
	}
?>